package org.xielei.thread;

import java.beans.Transient;

/**
 * Synchronized
 *
 * @author xielei
 * @date 2020/11/9
 */
public class Synchronized {

    private static long count = 10;

    public synchronized static long updateWithSync(String name, long a) {
        count -= a;
        System.out.println(name + ": " + count);
        try {
            Thread.sleep(100);
        } catch (InterruptedException e) {
            System.out.println(e);
        }
        return count;
    }

    public static void main(String[] args) {
        long a = 1;
        for (int i = 0; i < 10; i++) {
            new Thread(() -> {
                String name = Thread.currentThread().getName();
                updateWithSync(name, a);
            }).start();
        }
    }
}
